﻿using System;
using System.Collections;
using System.Text;
using System.Web;

public class CartObj
{
    public static void Add(string id)
    {
        if (id != "0")
        {
            Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
            if (hashtable == null)
            {
                hashtable = new Hashtable();
                hashtable.Add(id, 1);
                HttpContext.Current.Session["GoodsList" + Website.GetLanguage()] = hashtable;
            }
            else if (hashtable.Contains(id))
            {
                int num = ((int) hashtable[id]) + 1;
                hashtable[id] = num;
                HttpContext.Current.Session["GoodsList" + Website.GetLanguage()] = hashtable;
            }
            else
            {
                hashtable.Add(id, 1);
                HttpContext.Current.Session["GoodsList" + Website.GetLanguage()] = hashtable;
            }
        }
    }

    public static void Char()
    {
        Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
        if (hashtable != null)
        {
            hashtable.Clear();
        }
        HttpContext.Current.Session["GoodsList" + Website.GetLanguage()] = hashtable;
    }

    public static void Del(string id)
    {
        Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
        hashtable.Remove(id);
        HttpContext.Current.Session["GoodsList" + Website.GetLanguage()] = hashtable;
    }

    public static int GetGoodsCount()
    {
        Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
        if (hashtable == null)
        {
            return 0;
        }
        return hashtable.Count;
    }

    public static int GetGoodsNum(string id)
    {
        Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
        if (hashtable == null)
        {
            return 1;
        }
        return (int) hashtable[id];
    }

    public static string GetGross()
    {
        string str = (string) HttpContext.Current.Session["Gross" + Website.GetLanguage()];
        if (str == null)
        {
            str = "0.00";
        }
        return str;
    }

    public static void GrossChar()
    {
        HttpContext.Current.Session["Gross" + Website.GetLanguage()] = "0.00";
    }

    public static string IdList()
    {
        string str = "0";
        Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
        StringBuilder builder = new StringBuilder();
        if (hashtable == null)
        {
            str = "0";
        }
        else
        {
            foreach (DictionaryEntry entry in hashtable)
            {
                builder.AppendFormat("{0},", entry.Key);
            }
            str = builder.ToString().Trim(new char[] { ',' });
        }
        if ((str == "") | (str == null))
        {
            str = "0";
        }
        return str;
    }

    public static void SetGross(float grossNum)
    {
        HttpContext.Current.Session["Gross" + Website.GetLanguage()] = grossNum.ToString("0.00");
    }

    public static void UpDate(string id, int num)
    {
        Hashtable hashtable = (Hashtable) HttpContext.Current.Session["GoodsList" + Website.GetLanguage()];
        hashtable[id] = num;
        HttpContext.Current.Session["GoodsList" + Website.GetLanguage()] = hashtable;
    }
}

